#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/23 0023 9:29
# @Author  : wzy
# @Site    : 
# @File    : mock.py
# @Software: PyCharm
from mitmproxy import http
from Util.operate_json import operateJson
from Util.operate_pathUrll import pathinfo

import json
class MockServer:

    def request(self,flow):
        request_data = flow.request
        self.request_url = request_data.url
        request_data.host='127.0.0.1'
        request_data.port=5000

    def response(self,flow):
        if 'imooc' in self.request_url or 'mukewang' in self.request_url:
            response_data = flow.response
            host = self.request_url.split(".com")
            url = host[1]
            if "?" in host[1]:
                url = url.split("?")[0]
            data = json.dumps(operateJson.get_json_value(url))
            response_data.set_text(data)
addons = [
    MockServer()
]


